package org.jsrml.common.persistence;
import java.io.Serializable;

import org.apache.commons.lang.StringUtils;
import org.jsrml.common.util.UUIDGenerator;
import org.jsrml.common.util.UnitOfWork;

import com.alibaba.fastjson.annotation.JSONField;

@SuppressWarnings("serial")
public abstract class BaseCommand implements Serializable {
	
	private String commandId;
	private String sagaId;
	
	private String token;
	private RequestHead head;
	
	@JSONField(serialize = false)
	public UnitOfWork getUnitOfWork() {
		if (StringUtils.isBlank(commandId)) {
			setCommandId(UUIDGenerator.getUUID());
		}

		return UnitOfWork.getInstance(commandId, getSagaId());
	}
	
	public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
	}
	public RequestHead getHead() {
		return head;
	}
	public void setHead(RequestHead head) {
		this.head = head;
	}

	public String getCommandId() {
		return commandId;
	}

	public void setCommandId(String commandId) {
		this.commandId = commandId;
	}

	public String getSagaId() {
		return sagaId;
	}

	public void setSagaId(String sagaId) {
		this.sagaId = sagaId;
	}

}
